import datetime
import pandas as pd
from DataTools import datatool
from DataGeter import inputfomating


def futuredays(
    df,
    gap=5,
    pre="5",
    number_of_days=2,
    dirDic={
        "Main": "D:/StockDatas/",
        "basic": "basic/",
        "daily": "163_Daily_Bar/",
        "report": "Reports/",
        "temp": "temp/",
        "ticker": "History_ticker/",
        "mins": "History_mins/",
    },
):
    lastday = df.date.iloc[-1]
    lastday = datetime.datetime.strptime(lastday, "%Y-%m-%d %H:%M:%S")
    opendays = datatool.getTradedayinfo(
        MainPath=dirDic["Main"], subPath=dirDic["basic"], mode="openday"
    )
    futuredayL = []

    for g in range(gap * number_of_days):
        if int(lastday.hour) >= 15:
            lastday = lastday + datetime.timedelta(days=1)
            lastday = lastday + datetime.timedelta(minutes=30)
            lastday = lastday - datetime.timedelta(hours=6)
        elif int(lastday.hour) == 11 and int(lastday.minute) >= 29:
            lastday = lastday + datetime.timedelta(minutes=90)

        while True:
            if int(inputfomating.dateFormating(lastday, mode="S")) not in opendays:
                lastday = lastday + datetime.timedelta(days=1)
            else:
                break

        lastday = lastday + datetime.timedelta(minutes=(int(pre)))
        futuredayL.append(lastday.strftime("%Y-%m-%d %H:%M:%S"))
        
    df2 = pd.DataFrame(futuredayL, columns=["date"])
    df = pd.concat([df, df2])
    return df